package com.teaphy.coroutinecrawler.flow.operators

import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.*

fun main() = runBlocking{
    generateNumber().combineTransform(generateString()) {
        num, str ->
        emit("$num - $str")
    }.collect {
        println("接收到的数据是：$it")
    }

    println("Done")
}

suspend fun generateNumber() = flow {
    for (num in 0..10) {
        println("NumberFlow emmit: $num")
        emit(num)
        delay(100)
    }
}

suspend fun generateString() = flow {
    val list = listOf<String>("A", "B", "C", "D", "E", "F")
    for (str in list) {
        println("StringFlow emmit: $str")
        emit(str)
        delay(300)
    }
}